home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu247.dms / pu247.adf / Intuition / Gadgets / Example13.c < prev    next >
C/C++ Source or Header  |  1992-05-01  |  26KB  |  654 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Intuition               Amiga C Club       */
  7. /* Chapter: Gadgets                     Tulevagen 22       */
  8. /* File:    Example13.c                 181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-05-01                                       */
  11. /* Version: 1.10                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This example demonstrates how to use six string gadgets which */
  21. /* are automatically activated (selected) when the user release  */
  22. /* the gadget above.                                             */
  23.  
  24.  
  25.  
  26. /* We use Intuition: */
  27. #include <intuition/intuition.h>
  28.  
  29.  
  30. /* Maximum length of the string gadgets: */
  31. #define STRINGSIZE 50
  32.  
  33.  
  34. /* We are using the Intuition library: */
  35. struct IntuitionBase *IntuitionBase;
  36.  
  37.  
  38.  
  39. /* The coordinates for the box: */
  40. SHORT my_points[]=
  41. {
  42.    -7, -4, /* Start at position (-7, -4) */
  43.   200, -4, /* Draw a line to the right to position (200,-4) */
  44.   200, 11, /* Draw a line down to position (200,11) */
  45.    -7, 11, /* Draw a line to the right to position (-7,11) */
  46.    -7, -4  /* Finish of by drawing a line up to position (-7,-4) */ 
  47. };
  48.  
  49. /* The Border structure: */
  50. struct Border my_border=
  51. {
  52.   0, 0,        /* LeftEdge, TopEdge. */
  53.   1,           /* FrontPen, colour register 1. */
  54.   0,           /* BackPen, for the moment unused. */
  55.   JAM1,        /* DrawMode, draw the lines with colour 1. */
  56.   5,           /* Count, 5 pair of coordinates in the array. */
  57.   my_points,   /* XY, pointer to the array with the coordinates. */
  58.   NULL,        /* NextBorder, no other Border structures are connected. */
  59. };
  60.  
  61. UBYTE my_undo_buffer[STRINGSIZE]; /* Must be at least as big as my_buffer. */
  62.  
  63.  
  64.  
  65. /*****************/
  66. /* Textstring 1: */
  67. /*****************/
  68.  
  69. UBYTE my_buffer1[STRINGSIZE]; /* 50 characters including the NULL-sign. */
  70.  
  71. /* The IntuiText structure: */
  72. struct IntuiText text1=
  73. {
  74.   1,         /* FrontPen, colour register 1. */
  75.   0,         /* BackPen, colour register 0. */
  76.   JAM1,      /* DrawMode, draw the characters with colour 1, do not */
  77.              /* change the background. */ 
  78.   -77, 0,    /* LeftEdge, TopEdge. */
  79.   NULL,      /* ITextFont, use default font. */
  80.   "   Name:",/* IText, the text that will be printed. */
  81.   NULL,      /* NextText, no other IntuiText structures. */
  82. };
  83.  
  84. struct StringInfo string_info1=
  85. {
  86.   my_buffer1,      /* Buffer, pointer to a null-terminated string. */
  87.   my_undo_buffer,  /* UndoBuffer, pointer to a null-terminated string. */
  88.                    /* (Remember my_buffer is equal to &my_buffer[0]) */
  89.   0,               /* BufferPos, initial position of the cursor. */
  90.   50,              /* MaxChars, 50 characters + null-sign ('\0'). */
  91.   0,               /* DispPos, first character in the string should be */
  92.                    /* first character in the display. */
  93.  
  94.   /* Intuition initializes and maintaines these variables: */
  95.  
  96.   0,               /* UndoPos */
  97.   0,               /* NumChars */
  98.   0,               /* DispCount */
  99.   0, 0,            /* CLeft, CTop */
  100.   NULL,            /* LayerPtr */
  101.   NULL,            /* LongInt */
  102.   NULL,            /* AltKeyMap */
  103. };
  104.  
  105. struct Gadget gadget1=
  106. {
  107.   NULL,          /* NextGadget, no more gadgets in the list. */
  108.   92,            /* LeftEdge, 92 pixels out. */
  109.   30,            /* TopEdge, 30 lines down. */
  110.   198,           /* Width, 198 pixels wide. */
  111.   8,             /* Height, 8 pixels lines heigh. */
  112.   GADGHCOMP,     /* Flags, draw the select box in the complement */
  113.                  /* colours. Note: it actually only the cursor which */
  114.                  /* will be drawn in the complement colours (yellow). */
  115.                  /* If you set the flag GADGHNONE the cursor will not be */
  116.                  /* highlighted, and the user will therefore not be able */
  117.                  /* to see it. */
  118.   GADGIMMEDIATE| /* Activation, our program will recieve a message when */
  119.   RELVERIFY,     /* the user has selected this gadget, and when the user */
  120.                  /* has released it. */ 
  121.   STRGADGET,     /* GadgetType, a String gadget. */
  122.   (APTR) &my_border, /* GadgetRender, a pointer to our Border structure. */
  123.   NULL,          /* SelectRender, NULL since we do not supply the gadget */
  124.                  /* with an alternative image. */
  125.   &text1,        /* GadgetText, a pointer to our IntuiText structure. */
  126.   NULL,          /* MutualExclude, no mutual exclude. */
  127.   (APTR) &string_info1, /* SpecialInfo, a pointer to a StringInfo str. */
  128.   0,             /* GadgetID, no id. */
  129.   NULL           /* UserData, no user data connected to the gadget. */
  130. };
  131.  
  132.  
  133.  
  134. /*****************/
  135. /* Textstring 2: */
  136. /*****************/
  137.  
  138. UBYTE my_buffer2[STRINGSIZE]; /* 50 characters including the NULL-sign. */
  139.  
  140. /* The IntuiText structure: */
  141. struct IntuiText text2=
  142. {
  143.   1,         /* FrontPen, colour register 1. */
  144.   0,         /* BackPen, colour register 0. */
  145.   JAM1,      /* DrawMode, draw the characters with colour 1, do not */
  146.              /* change the background. */ 
  147.   -77, 0,    /* LeftEdge, TopEdge. */
  148.   NULL,      /* ITextFont, use default font. */
  149.   "Address:",/* IText, the text that will be printed. */
  150.   NULL,      /* NextText, no other IntuiText structures. */
  151. };
  152.  
  153. struct StringInfo string_info2=
  154. {
  155.   my_buffer2,      /* Buffer, pointer to a null-terminated string. */
  156.   my_undo_buffer,  /* UndoBuffer, pointer to a null-terminated string. */
  157.                    /* (Remember my_buffer is equal to &my_buffer[0]) */
  158.   0,               /* BufferPos, initial position of the cursor. */
  159.   50,              /* MaxChars, 50 characters + null-sign ('\0'). */
  160.   0,               /* DispPos, first character in the string should be */
  161.                    /* first character in the display. */
  162.  
  163.   /* Intuition initializes and maintaines these variables: */
  164.  
  165.   0,               /* UndoPos */
  166.   0,               /* NumChars */
  167.   0,               /* DispCount */
  168.   0, 0,            /* CLeft, CTop */
  169.   NULL,            /* LayerPtr */
  170.   NULL,            /* LongInt */
  171.   NULL,            /* AltKeyMap */
  172. };
  173.  
  174. struct Gadget gadget2=
  175. {
  176.   &gadget1,      /* NextGadget, no more gadgets in the list. */
  177.   92,            /* LeftEdge, 92 pixels out. */
  178.   50,            /* TopEdge, 50 lines down. */
  179.   198,           /* Width, 198 pixels wide. */
  180.   8,             /* Height, 8 pixels lines heigh. */
  181.   GADGHCOMP,     /* Flags, draw the select box in the complement */
  182.                  /* colours. Note: it actually only the cursor which */
  183.                  /* will be drawn in the complement colours (yellow). */
  184.                  /* If you set the flag GADGHNONE the cursor will not be */
  185.                  /* highlighted, and the user will therefore not be able */
  186.                  /* to see it. */
  187.   GADGIMMEDIATE| /* Activation, our program will recieve a message when */
  188.   RELVERIFY,     /* the user has selected this gadget, and when the user */
  189.                  /* has released it. */ 
  190.   STRGADGET,     /* GadgetType, a String gadget. */
  191.   (APTR) &my_border, /* GadgetRender, a pointer to our Border structure. */
  192.   NULL,          /* SelectRender, NULL since we do not supply the gadget */
  193.                  /* with an alternative image. */
  194.   &text2,        /* GadgetText, a pointer to our IntuiText structure. */
  195.   NULL,          /* MutualExclude, no mutual exclude. */
  196.   (APTR) &string_info2, /* SpecialInfo, a pointer to a StringInfo str. */
  197.   0,             /* GadgetID, no id. */
  198.   NULL           /* UserData, no user data connected to the gadget. */
  199. };
  200.  
  201.  
  202.  
  203. /*****************/
  204. /* Textstring 3: */
  205. /*****************/
  206.  
  207. UBYTE my_buffer3[STRINGSIZE]; /* 50 characters including the NULL-sign. */
  208.  
  209. /* The IntuiText structure: */
  210. struct IntuiText text3=
  211. {
  212.   1,         /* FrontPen, colour register 1. */
  213.   0,         /* BackPen, colour register 0. */
  214.   JAM1,      /* DrawMode, draw the characters with colour 1, do not */
  215.              /* change the background. */ 
  216.   -77, 0,    /* LeftEdge, TopEdge. */
  217.   NULL,      /* ITextFont, use default font. */
  218.   "   City:",/* IText, the text that will be printed. */
  219.   NULL,      /* NextText, no other IntuiText structures. */
  220. };
  221.  
  222. struct StringInfo string_info3=
  223. {
  224.   my_buffer3,      /* Buffer, pointer to a null-terminated string. */
  225.   my_undo_buffer,  /* UndoBuffer, pointer to a null-terminated string. */
  226.                    /* (Remember my_buffer is equal to &my_buffer[0]) */
  227.   0,               /* BufferPos, initial position of the cursor. */
  228.   50,              /* MaxChars, 50 characters + null-sign ('\0'). */
  229.   0,               /* DispPos, first character in the string should be */
  230.                    /* first character in the display. */
  231.  
  232.   /* Intuition initializes and maintaines these variables: */
  233.  
  234.   0,               /* UndoPos */
  235.   0,               /* NumChars */
  236.   0,               /* DispCount */
  237.   0, 0,            /* CLeft, CTop */
  238.   NULL,            /* LayerPtr */
  239.   NULL,            /* LongInt */
  240.   NULL,            /* AltKeyMap */
  241. };
  242.  
  243. struct Gadget gadget3=
  244. {
  245.   &gadget2,      /* NextGadget, no more gadgets in the list. */
  246.   92,            /* LeftEdge, 92 pixels out. */
  247.   70,            /* TopEdge, 70 lines down. */
  248.   198,           /* Width, 198 pixels wide. */
  249.   8,             /* Height, 8 pixels lines heigh. */
  250.   GADGHCOMP,     /* Flags, draw the select box in the complement */
  251.                  /* colours. Note: it actually only the cursor which */
  252.                  /* will be drawn in the complement colours (yellow). */
  253.                  /* If you set the flag GADGHNONE the cursor will not be */
  254.                  /* highlighted, and the user will therefore not be able */
  255.                  /* to see it. */
  256.   GADGIMMEDIATE| /* Activation, our program will recieve a message when */
  257.   RELVERIFY,     /* the user has selected this gadget, and when the user */
  258.                  /* has released it. */ 
  259.   STRGADGET,     /* GadgetType, a String gadget. */
  260.   (APTR) &my_border, /* GadgetRender, a pointer to our Border structure. */
  261.   NULL,          /* SelectRender, NULL since we do not supply the gadget */
  262.                  /* with an alternative image. */
  263.   &text3,        /* GadgetText, a pointer to our IntuiText structure. */
  264.   NULL,          /* MutualExclude, no mutual exclude. */
  265.   (APTR) &string_info3, /* SpecialInfo, a pointer to a StringInfo str. */
  266.   0,             /* GadgetID, no id. */
  267.   NULL           /* UserData, no user data connected to the gadget. */
  268. };
  269.  
  270.  
  271.  
  272. /*****************/
  273. /* Textstring 4: */
  274. /*****************/
  275.  
  276. UBYTE my_buffer4[STRINGSIZE]; /* 50 characters including the NULL-sign. */
  277.  
  278. /* The IntuiText structure: */
  279. struct IntuiText text4=
  280. {
  281.   1,         /* FrontPen, colour register 1. */
  282.   0,         /* BackPen, colour register 0. */
  283.   JAM1,      /* DrawMode, draw the characters with colour 1, do not */
  284.              /* change the background. */ 
  285.   -77, 0,    /* LeftEdge, TopEdge. */
  286.   NULL,      /* ITextFont, use default font. */
  287.   "  State:",/* IText, the text that will be printed. */
  288.   NULL,      /* NextText, no other IntuiText structures. */
  289. };
  290.  
  291. struct StringInfo string_info4=
  292. {
  293.   my_buffer4,      /* Buffer, pointer to a null-terminated string. */
  294.   my_undo_buffer,  /* UndoBuffer, pointer to a null-terminated string. */
  295.                    /* (Remember my_buffer is equal to &my_buffer[0]) */
  296.   0,               /* BufferPos, initial position of the cursor. */
  297.   50,              /* MaxChars, 50 characters + null-sign ('\0'). */
  298.   0,               /* DispPos, first character in the string should be */
  299.                    /* first character in the display. */
  300.  
  301.   /* Intuition initializes and maintaines these variables: */
  302.  
  303.   0,               /* UndoPos */
  304.   0,               /* NumChars */
  305.   0,               /* DispCount */
  306.   0, 0,            /* CLeft, CTop */
  307.   NULL,            /* LayerPtr */
  308.   NULL,            /* LongInt */
  309.   NULL,            /* AltKeyMap */
  310. };
  311.  
  312. struct Gadget gadget4=
  313. {
  314.   &gadget3,      /* NextGadget, no more gadgets in the list. */
  315.   92,            /* LeftEdge, 92 pixels out. */
  316.   90,            /* TopEdge, 90 lines down. */
  317.   198,           /* Width, 198 pixels wide. */
  318.   8,             /* Height, 8 pixels lines heigh. */
  319.   GADGHCOMP,     /* Flags, draw the select box in the complement */
  320.                  /* colours. Note: it actually only the cursor which */
  321.                  /* will be drawn in the complement colours (yellow). */
  322.                  /* If you set the flag GADGHNONE the cursor will not be */
  323.                  /* highlighted, and the user will therefore not be able */
  324.                  /* to see it. */
  325.   GADGIMMEDIATE| /* Activation, our program will recieve a message when */
  326.   RELVERIFY,     /* the user has selected this gadget, and when the user */
  327.                  /* has released it. */ 
  328.   STRGADGET,     /* GadgetType, a String gadget. */
  329.   (APTR) &my_border, /* GadgetRender, a pointer to our Border structure. */
  330.   NULL,          /* SelectRender, NULL since we do not supply the gadget */
  331.                  /* with an alternative image. */
  332.   &text4,        /* GadgetText, a pointer to our IntuiText structure. */
  333.   NULL,          /* MutualExclude, no mutual exclude. */
  334.   (APTR) &string_info4, /* SpecialInfo, a pointer to a StringInfo str. */
  335.   0,             /* GadgetID, no id. */
  336.   NULL           /* UserData, no user data connected to the gadget. */
  337. };
  338.  
  339.  
  340.  
  341. /*****************/
  342. /* Textstring 5: */
  343. /*****************/
  344.  
  345. UBYTE my_buffer5[STRINGSIZE]; /* 50 characters including the NULL-sign. */
  346.  
  347. /* The IntuiText structure: */
  348. struct IntuiText text5=
  349. {
  350.   1,         /* FrontPen, colour register 1. */
  351.   0,         /* BackPen, colour register 0. */
  352.   JAM1,      /* DrawMode, draw the characters with colour 1, do not */
  353.              /* change the background. */ 
  354.   -77, 0,    /* LeftEdge, TopEdge. */
  355.   NULL,      /* ITextFont, use default font. */
  356.   "Country:",/* IText, the text that will be printed. */
  357.   NULL,      /* NextText, no other IntuiText structures. */
  358. };
  359.  
  360. struct StringInfo string_info5=
  361. {
  362.   my_buffer5,      /* Buffer, pointer to a null-terminated string. */
  363.   my_undo_buffer,  /* UndoBuffer, pointer to a null-terminated string. */
  364.                    /* (Remember my_buffer is equal to &my_buffer[0]) */
  365.   0,               /* BufferPos, initial position of the cursor. */
  366.   50,              /* MaxChars, 50 characters + null-sign ('\0'). */
  367.   0,               /* DispPos, first character in the string should be */
  368.                    /* first character in the display. */
  369.  
  370.   /* Intuition initializes and maintaines these variables: */
  371.  
  372.   0,               /* UndoPos */
  373.   0,               /* NumChars */
  374.   0,               /* DispCount */
  375.   0, 0,            /* CLeft, CTop */
  376.   NULL,            /* LayerPtr */
  377.   NULL,            /* LongInt */
  378.   NULL,            /* AltKeyMap */
  379. };
  380.  
  381. struct Gadget gadget5=
  382. {
  383.   &gadget4,      /* NextGadget, no more gadgets in the list. */
  384.   92,            /* LeftEdge, 92 pixels out. */
  385.   110,           /* TopEdge, 110 lines down. */
  386.   198,           /* Width, 198 pixels wide. */
  387.   8,             /* Height, 8 pixels lines heigh. */
  388.   GADGHCOMP,     /* Flags, draw the select box in the complement */
  389.                  /* colours. Note: it actually only the cursor which */
  390.                  /* will be drawn in the complement colours (yellow). */
  391.                  /* If you set the flag GADGHNONE the cursor will not be */
  392.                  /* highlighted, and the user will therefore not be able */
  393.                  /* to see it. */
  394.   GADGIMMEDIATE| /* Activation, our program will recieve a message when */
  395.   RELVERIFY,     /* the user has selected this gadget, and when the user */
  396.                  /* has released it. */ 
  397.   STRGADGET,     /* GadgetType, a String gadget. */
  398.   (APTR) &my_border, /* GadgetRender, a pointer to our Border structure. */
  399.   NULL,          /* SelectRender, NULL since we do not supply the gadget */
  400.                  /* with an alternative image. */
  401.   &text5,        /* GadgetText, a pointer to our IntuiText structure. */
  402.   NULL,          /* MutualExclude, no mutual exclude. */
  403.   (APTR) &string_info5, /* SpecialInfo, a pointer to a StringInfo str. */
  404.   0,             /* GadgetID, no id. */
  405.   NULL           /* UserData, no user data connected to the gadget. */
  406. };
  407.  
  408.  
  409.  
  410. /*****************/
  411. /* Textstring 6: */
  412. /*****************/
  413.  
  414. UBYTE my_buffer6[STRINGSIZE]; /* 50 characters including the NULL-sign. */
  415.  
  416. /* The IntuiText structure: */
  417. struct IntuiText text6=
  418. {
  419.   1,         /* FrontPen, colour register 1. */
  420.   0,         /* BackPen, colour register 0. */
  421.   JAM1,      /* DrawMode, draw the characters with colour 1, do not */
  422.              /* change the background. */ 
  423.   -77, 0,    /* LeftEdge, TopEdge. */
  424.   NULL,      /* ITextFont, use default font. */
  425.   "  Phone:",/* IText, the text that will be printed. */
  426.   NULL,      /* NextText, no other IntuiText structures. */
  427. };
  428.  
  429. struct StringInfo string_info6=
  430. {
  431.   my_buffer6,      /* Buffer, pointer to a null-terminated string. */
  432.   my_undo_buffer,  /* UndoBuffer, pointer to a null-terminated string. */
  433.                    /* (Remember my_buffer is equal to &my_buffer[0]) */
  434.   0,               /* BufferPos, initial position of the cursor. */
  435.   50,              /* MaxChars, 50 characters + null-sign ('\0'). */
  436.   0,               /* DispPos, first character in the string should be */
  437.                    /* first character in the display. */
  438.  
  439.   /* Intuition initializes and maintaines these variables: */
  440.  
  441.   0,               /* UndoPos */
  442.   0,               /* NumChars */
  443.   0,               /* DispCount */
  444.   0, 0,            /* CLeft, CTop */
  445.   NULL,            /* LayerPtr */
  446.   NULL,            /* LongInt */
  447.   NULL,            /* AltKeyMap */
  448. };
  449.  
  450. struct Gadget gadget6=
  451. {
  452.   &gadget5,      /* NextGadget, no more gadgets in the list. */
  453.   92,            /* LeftEdge, 92 pixels out. */
  454.   130,           /* TopEdge, 130 lines down. */
  455.   198,           /* Width, 198 pixels wide. */
  456.   8,             /* Height, 8 pixels lines heigh. */
  457.   GADGHCOMP,     /* Flags, draw the select box in the complement */
  458.                  /* colours. Note: it actually only the cursor which */
  459.                  /* will be drawn in the complement colours (yellow). */
  460.                  /* If you set the flag GADGHNONE the cursor will not be */
  461.                  /* highlighted, and the user will therefore not be able */
  462.                  /* to see it. */
  463.   GADGIMMEDIATE| /* Activation, our program will recieve a message when */
  464.   RELVERIFY,     /* the user has selected this gadget, and when the user */
  465.                  /* has released it. */ 
  466.   STRGADGET,     /* GadgetType, a String gadget. */
  467.   (APTR) &my_border, /* GadgetRender, a pointer to our Border structure. */
  468.   NULL,          /* SelectRender, NULL since we do not supply the gadget */
  469.                  /* with an alternative image. */
  470.   &text6,        /* GadgetText, a pointer to our IntuiText structure. */
  471.   NULL,          /* MutualExclude, no mutual exclude. */
  472.   (APTR) &string_info6, /* SpecialInfo, a pointer to a StringInfo str. */
  473.   0,             /* GadgetID, no id. */
  474.   NULL           /* UserData, no user data connected to the gadget. */
  475. };
  476.  
  477.  
  478.  
  479.  
  480. /* Declare a pointer to a Window structure: */ 
  481. struct Window *my_window;
  482.  
  483. /* Declare and initialize your NewWindow structure: */
  484. struct NewWindow my_new_window=
  485. {
  486.   0,             /* LeftEdge    x position of the window. */
  487.   10,            /* TopEdge     y positio of the window. */
  488.   400,           /* Width       400 pixels wide. */
  489.   180,           /* Height      180 lines high. */
  490.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  491.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  492.   CLOSEWINDOW|   /* IDCMPFlags  The window will give us a message if the */
  493.                  /*             user has selected the Close window gad, */
  494.   GADGETDOWN|    /*             or a gadget has been pressed on, or */
  495.   GADGETUP,      /*             a gadge has been released. */
  496.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  497.   WINDOWCLOSE|   /*             Close Gadget. */
  498.   WINDOWDRAG|    /*             Drag gadget. */
  499.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  500.   WINDOWSIZING|  /*             Sizing Gadget. */
  501.   ACTIVATE,      /*             The window should be Active when opened. */
  502.   &gadget6,      /* FirstGadget A pointer to the String gadget. */
  503.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  504.   "Automatically activated string gadgets",/* Title       Title of the window. */
  505.   NULL,          /* Screen      Connected to the Workbench Screen. */
  506.   NULL,          /* BitMap      No Custom BitMap. */
  507.   400,           /* MinWidth    We will not allow the window to become */
  508.   180,           /* MinHeight   smaller than 400 x 180, and not bigger */
  509.   640,           /* MaxWidth    than 640 x 200. */
  510.   200,           /* MaxHeight */
  511.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  512. };
  513.  
  514.  
  515.  
  516. main()
  517. {
  518.   /* Boolean variable used for the while loop: */
  519.   BOOL close_me;
  520.  
  521.   /* Declare a variable in which we will store the IDCMP flag: */
  522.   ULONG class;
  523.   CPTR address;
  524.  
  525.   /* Declare a pointer to an IntuiMessage structure: */
  526.   struct IntuiMessage *my_message;
  527.  
  528.  
  529.  
  530.   /* Put some text (thi time nothing) into the buffer strings: */
  531.   strcpy( my_buffer1, "" );
  532.   strcpy( my_buffer2, "" );
  533.   strcpy( my_buffer3, "" );
  534.   strcpy( my_buffer4, "" );
  535.   strcpy( my_buffer5, "" );
  536.   strcpy( my_buffer6, "" );
  537.  
  538.  
  539.  
  540.   /* Before we can use Intuition we need to open the Intuition Library: */
  541.   IntuitionBase = (struct IntuitionBase *)
  542.     OpenLibrary( "intuition.library", 0 );
  543.   
  544.   if( IntuitionBase == NULL )
  545.     exit(); /* Could NOT open the Intuition Library! */
  546.  
  547.  
  548.  
  549.   /* We will now try to open the window: */
  550.   my_window = (struct Window *) OpenWindow( &my_new_window );
  551.   
  552.   /* Have we opened the window succesfully? */
  553.   if(my_window == NULL)
  554.   {
  555.     /* Could NOT open the Window! */
  556.     
  557.     /* Close the Intuition Library since we have opened it: */
  558.     CloseLibrary( IntuitionBase );
  559.  
  560.     exit();  
  561.   }
  562.   /* We have opened the window, and everything seems to be OK. */
  563.  
  564.  
  565.  
  566.   /* Activate the first gadget: */
  567.   ActivateGadget( &gadget1, my_window, NULL );
  568.  
  569.  
  570.   close_me = FALSE;
  571.  
  572.   /* Stay in the while loop until the user has selected the Close window */
  573.   /* gadget: */
  574.   while( close_me == FALSE )
  575.   {
  576.     /* Wait until we have recieved a message: */
  577.     Wait( 1 << my_window->UserPort->mp_SigBit );
  578.  
  579.     /* As long as we can collect messages sucessfully we stay in the loop: */
  580.     while( my_message = (struct IntuiMessage *) GetMsg( my_window->UserPort) )
  581.     {
  582.       /* After we have collected the message we can read it, and save any */
  583.       /* important values which we maybe want to check later: */
  584.  
  585.       /* Save the IDCMP flag: */
  586.       class    = my_message->Class;
  587.  
  588.             /* Save the address of the sender: */
  589.       address  = (CPTR) my_message->IAddress;
  590.   
  591.       /* After we have read it we reply as fast as possible: */
  592.       /* REMEMBER! Do never try to read a message after you have replied! */
  593.       /* Some other process has maybe changed it. */
  594.       ReplyMsg( my_message );
  595.   
  596.       /* Check which IDCMP flag was sent: */
  597.       switch( class )
  598.       {
  599.         case CLOSEWINDOW:  /* The user selected the Close window gadget! */
  600.                close_me=TRUE;
  601.                break;
  602.                
  603.         case GADGETDOWN:
  604.                        /* The user has selected a String gadget: */
  605.                /* (Clicked inside the select box) */
  606.                printf("A string gadget was selected.\n");
  607.                break;
  608.                
  609.         case GADGETUP:
  610.                        /* The user has released a String gadget: */
  611.                /* (Pressed ENTER or RETURN) */
  612.  
  613.                /* If gadget1 was released, activate gadget2, */
  614.                              /* if gadget2 was released, activate gadget3, */
  615.                              /* and so on...                               */
  616.                              if( address == (CPTR) &gadget1 )
  617.                  ActivateGadget( &gadget2, my_window, NULL );
  618.                if( address == (CPTR) &gadget2 )
  619.                  ActivateGadget( &gadget3, my_window, NULL );
  620.                if( address == (CPTR) &gadget3 )
  621.                  ActivateGadget( &gadget4, my_window, NULL );
  622.                if( address == (CPTR) &gadget4 )
  623.                  ActivateGadget( &gadget5, my_window, NULL );
  624.                if( address == (CPTR) &gadget5 )
  625.                  ActivateGadget( &gadget6, my_window, NULL );
  626.                if( address == (CPTR) &gadget6 )
  627.                  ActivateGadget( &gadget1, my_window, NULL );
  628.  
  629.                break;
  630.       }
  631.     }
  632.   }
  633.  
  634.  
  635.   /* We should always close the windows we have opened before we leave: */
  636.   CloseWindow( my_window );
  637.  
  638.  
  639.   /* Print out the contents of the strings: */
  640.   printf("   Name: %s\n", string_info1.Buffer);
  641.   printf("Address: %s\n", string_info2.Buffer);
  642.   printf("   City: %s\n", string_info3.Buffer);
  643.   printf("  State: %s\n", string_info4.Buffer);
  644.   printf("Country: %s\n", string_info5.Buffer);
  645.   printf("  Phone: %s\n", string_info6.Buffer);
  646.  
  647.  
  648.  
  649.   /* Close the Intuition Library since we have opened it: */
  650.   CloseLibrary( IntuitionBase );
  651.  
  652.   /* THE END */
  653. }
  654.